#import "PublishRecruitUI.h"
#import "IQKeyboardManager.h"
@interface PublishRecruitUI ()

@end

@implementation PublishRecruitUI
@synthesize kdName,weight,age,bdImgPath,serverPath,avatar,reqJobName,desc;
@synthesize email,linkman,gender,addr;
-(void)selectTypeFn:(UIButton*)btn{
    int tag=btn.tag-8000;
    NSLog(@"tag=====%d",tag);
    job_title=jobTitleData[tag];
    if (but) {
        [but removeFromSuperview];
    }
    [table reloadData];
    
    
}
-(void)showJobTypeFn{
    if(shareItemView){
        [shareItemView removeFromSuperview];
    }
    shareItemView=[[UIView alloc] initWithFrame:CGRectMake(30,57,260,420)];
    [shareItemView.layer setMasksToBounds:YES];
    shareItemView.backgroundColor=[UIColor whiteColor];
    
    
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    if (but) {
        [but removeFromSuperview];
    }
    but = [UIButton buttonWithType:UIButtonTypeCustom];
    int  h=[Tools getScreenHeight];
    [but setFrame:CGRectMake(0, 64, 320, h)];
    but.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    shareItemView.center =CGPointMake(160, 60+160);
    shareItemView.alpha=1.0;
    [but addSubview:shareItemView];
    
    [but addTarget:self action:@selector(removeShareView2) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:but];
    
    
    
    
    int  y0=50;
    
    int  y=127;
    
    
    //
    
    
    //
   
    
    
    //
    
    UIScrollView* sv=[[UIScrollView alloc] initWithFrame:CGRectMake(0,10, 320, 400)];
    
    //sv.accessibilityActivationPoint = CGPointMake(110*data.count, 100);
    sv.contentSize = CGSizeMake(210,
                                40*jobTitleData.count+40);
    sv.showsHorizontalScrollIndicator = YES;
    sv.delegate = self;
    [shareItemView addSubview:sv];
    
    for(int i=0;i<jobTitleData.count;i++){
        UIButton* btn=[[UIButton  alloc] initWithFrame:CGRectMake(0, 30+40*i, 260, 40)];
        [btn addTarget:self action:@selector(selectTypeFn:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag=8000+i;
        [sv addSubview:btn];
        
        NSString*  str=jobTitleData[i];
        UILabel*  yzLb=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 260, 39.5)];
        yzLb.text=str;
        yzLb.textColor=[UIColor darkGrayColor];
        yzLb.font=[UIFont systemFontOfSize:18];
        yzLb.textAlignment=NSTextAlignmentCenter;
        [btn addSubview:yzLb];
        //
        UIImageView* line=[[UIImageView alloc] initWithFrame:CGRectMake(0,39.5, 320, 0.5)];
        line.layer.backgroundColor=[[UIColor colorWithHexString:@"bfbfbf"] CGColor];
        [btn addSubview:line];
    }
    
    
    
    
    
    UIImageView* iv=[[UIImageView alloc] initWithFrame:CGRectMake(30, 70, 200, 40)];
    iv.layer.borderColor=[[UIColor colorWithHexString:@"bfbfbf"] CGColor];
    iv.layer.borderWidth=0.5;
    //[shareItemView addSubview:iv];
    
    
    
    
}



-(void)jbFn{
    recruit_type=1;
    
    UIImage* jb=[UIImage imageNamed:@"jb_focus"];
    
    UIImage* ktv=[UIImage imageNamed:@"ktv"];
    
    UIImage* yzh=[UIImage imageNamed:@"yzh"];
    
    NSArray* jbArray=[jbBtn subviews];
    for(UIView* v in jbArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [jbBtn setBackgroundImage:jb forState:0];
    UILabel* jbLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    jbLb.text=@"酒吧";
    jbLb.textAlignment=NSTextAlignmentCenter;
    jbLb.textColor=[UIColor whiteColor];
    jbLb.backgroundColor=[UIColor clearColor];
    [jbBtn addSubview:jbLb];
    
    NSArray* ktvArray=[ktvBtn subviews];
    for(UIView* v in ktvArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [ktvBtn setBackgroundImage:ktv forState:0];
    
    UILabel*  ktvLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    ktvLb.text=@"KTV";
    ktvLb.textAlignment=NSTextAlignmentCenter;
    ktvLb.textColor=[UIColor darkGrayColor];
    ktvLb.backgroundColor=[UIColor clearColor];
    [ktvBtn addSubview:ktvLb];
    
    NSArray* yzhArray=[yzhBtn subviews];
    for(UIView* v in yzhArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [yzhBtn setBackgroundImage:yzh forState:0];
    UILabel*  yzhLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    yzhLb.text=@"会所";
    yzhLb.textAlignment=NSTextAlignmentCenter;
    yzhLb.textColor=[UIColor darkGrayColor];
    yzhLb.backgroundColor=[UIColor clearColor];
    [yzhBtn addSubview:yzhLb];
    
    
    
    
    
    
}

-(void)ktvFn{
    recruit_type=2;
    
    
    
    UIImage* jb=[UIImage imageNamed:@"jb"];
    
    UIImage* ktv=[UIImage imageNamed:@"ktv_focus"];
    
    UIImage* yzh=[UIImage imageNamed:@"yzh"];
    
    NSArray* jbArray=[jbBtn subviews];
    for(UIView* v in jbArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [jbBtn setBackgroundImage:jb forState:0];
    UILabel* jbLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    jbLb.text=@"酒吧";
    jbLb.textAlignment=NSTextAlignmentCenter;
    jbLb.textColor=[UIColor darkGrayColor];
    jbLb.backgroundColor=[UIColor clearColor];
    [jbBtn addSubview:jbLb];
    
    NSArray* ktvArray=[ktvBtn subviews];
    for(UIView* v in ktvArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [ktvBtn setBackgroundImage:ktv forState:0];
    
    UILabel*  ktvLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    ktvLb.text=@"KTV";
    ktvLb.textAlignment=NSTextAlignmentCenter;
    ktvLb.textColor=[UIColor whiteColor];
    ktvLb.backgroundColor=[UIColor clearColor];
    [ktvBtn addSubview:ktvLb];
    
    NSArray* yzhArray=[yzhBtn subviews];
    for(UIView* v in yzhArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [yzhBtn setBackgroundImage:yzh forState:0];
    UILabel*  yzhLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    yzhLb.text=@"会所";
    yzhLb.textAlignment=NSTextAlignmentCenter;
    yzhLb.textColor=[UIColor darkGrayColor];
    yzhLb.backgroundColor=[UIColor clearColor];
    [yzhBtn addSubview:yzhLb];
    
    
    
    
    
    
}
-(void)yzhFn{
    recruit_type=3;
    
    
    
    UIImage* jb=[UIImage imageNamed:@"jb"];
    
    UIImage* ktv=[UIImage imageNamed:@"ktv"];
    
    UIImage* yzh=[UIImage imageNamed:@"yzh_focus"];
    
    NSArray* jbArray=[jbBtn subviews];
    for(UIView* v in jbArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [jbBtn setBackgroundImage:jb forState:0];
    UILabel* jbLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    jbLb.text=@"酒吧";
    jbLb.textAlignment=NSTextAlignmentCenter;
    jbLb.textColor=[UIColor darkGrayColor];
    jbLb.backgroundColor=[UIColor clearColor];
    [jbBtn addSubview:jbLb];
    
    NSArray* ktvArray=[ktvBtn subviews];
    for(UIView* v in ktvArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [ktvBtn setBackgroundImage:ktv forState:0];
    
    UILabel*  ktvLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    ktvLb.text=@"KTV";
    ktvLb.textAlignment=NSTextAlignmentCenter;
    ktvLb.textColor=[UIColor darkGrayColor];
    ktvLb.backgroundColor=[UIColor clearColor];
    [ktvBtn addSubview:ktvLb];
    
    NSArray* yzhArray=[yzhBtn subviews];
    for(UIView* v in yzhArray){
        if ([v isKindOfClass:[UILabel class]]) {
            [v removeFromSuperview];
        }
    }
    [yzhBtn setBackgroundImage:yzh forState:0];
    UILabel*  yzhLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    yzhLb.text=@"会所";
    yzhLb.textAlignment=NSTextAlignmentCenter;
    yzhLb.textColor=[UIColor whiteColor];
    yzhLb.backgroundColor=[UIColor clearColor];
    [yzhBtn addSubview:yzhLb];
    
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[IQKeyboardManager sharedManager] setShouldToolbarUsesTextFieldTintColor:YES];
    
}

-(void)backFn{
    [self.navigationController popViewControllerAnimated:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.gender=1;//默认是男人     2：女人
    recruit_type=1;
    job_title=@"";
    
    k=0;
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIImage* jb=[UIImage imageNamed:@"jb_focus"];
    
    UIImage* ktv=[UIImage imageNamed:@"ktv"];
    
    UIImage* yzh=[UIImage imageNamed:@"yzh"];
    
    jbBtn=[[UIButton alloc] initWithFrame:CGRectMake(1, 0, 320/3, 44)];
    [jbBtn setBackgroundImage:jb forState:0];
    [jbBtn addTarget:self action:@selector(jbFn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:jbBtn];
    UILabel* jbLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    jbLb.text=@"酒吧";
    jbLb.textAlignment=NSTextAlignmentCenter;
    jbLb.textColor=[UIColor whiteColor];
    jbLb.backgroundColor=[UIColor clearColor];
    [jbBtn addSubview:jbLb];
    
    ktvBtn=[[UIButton alloc] initWithFrame:CGRectMake(320/3+1, 0, 320/3, 44)];
    [ktvBtn setBackgroundImage:ktv forState:0];
    [ktvBtn addTarget:self action:@selector(ktvFn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:ktvBtn];
    
    UILabel*  ktvLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    ktvLb.text=@"KTV";
    ktvLb.textAlignment=NSTextAlignmentCenter;
    ktvLb.textColor=[UIColor darkGrayColor];
    ktvLb.backgroundColor=[UIColor clearColor];
    [ktvBtn addSubview:ktvLb];
    
    
    yzhBtn=[[UIButton alloc] initWithFrame:CGRectMake(320*2/3, 0, 320/3, 44)];
    [yzhBtn setBackgroundImage:yzh forState:0];
    [yzhBtn addTarget:self action:@selector(yzhFn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:yzhBtn];
    
    UILabel*  yzhLb=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320/3, 44)];
    yzhLb.text=@"会所";
    yzhLb.textAlignment=NSTextAlignmentCenter;
    yzhLb.textColor=[UIColor darkGrayColor];
    yzhLb.backgroundColor=[UIColor clearColor];
    [yzhBtn addSubview:yzhLb];
    
    
    
    
    
    UIImage *headImg=[UIImage imageNamed:@"navigation.png"];
    headImg=[Tools resizeImageToSize:headImg toSize:CGSizeMake(320, 44)];
    UINavigationBar *navBar = self.navigationController.navigationBar;
#define kSCNavBarImageTag 10
    if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
        [navBar setBackgroundImage:headImg forBarMetrics:UIBarMetricsDefault];
        UILabel* titleLb=[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 120, 44)];
        titleLb.text=@"发布招聘信息";
        titleLb.backgroundColor=[UIColor clearColor];
        titleLb.textAlignment=NSTextAlignmentCenter;
        titleLb.textColor=[UIColor whiteColor];
        self.navigationItem.titleView=titleLb;
        
    }
    else
    {
        UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];
        if (imageView == nil)
        {
            imageView = [[UIImageView alloc] initWithImage:
                         headImg];
            [imageView setTag:kSCNavBarImageTag];
            [navBar insertSubview:imageView atIndex:0];
            
            UILabel* titleLb=[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 120, 44)];
            titleLb.text=@"发布招聘信息";
            titleLb.backgroundColor=[UIColor clearColor];
            titleLb.textAlignment=NSTextAlignmentCenter;
            titleLb.textColor=[UIColor whiteColor];
            self.navigationItem.titleView=titleLb;
            
        }
        
    }
    int h=[Tools getScreenHeight];
    
    UIButton* cancelBtn= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
    [cancelBtn addTarget:self action:@selector(backFn) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect frame_1= CGRectMake(0, 7, 40, 30);
    UIImageView*  backView=[[UIImageView alloc] initWithFrame:frame_1];
    UIImage* image= [UIImage imageNamed:@"newback"];
    backView.image=image;
    [cancelBtn addSubview:backView];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:cancelBtn];
    
    
//    UIButton* okBtn= [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
//    [okBtn addTarget:self action:@selector(okFn) forControlEvents:UIControlEventTouchUpInside];
//    
//    
//    UILabel*  okLb=[[UILabel alloc] initWithFrame:frame_1];
//    okLb.text=@"确定";
//    okLb.textColor=[UIColor whiteColor];
//    [okBtn addSubview:okLb];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:okBtn];
    
    
    
    
    
    table=[[UITableView alloc] initWithFrame:CGRectMake(0, 44, 320, h)];
    table.contentInset=UIEdgeInsetsMake(0, 0, 170, 0);
    table.delegate=self;
    table.dataSource=self;
    table.separatorStyle=NO;
    [self.view addSubview:table];
    //
    jobTitleData=@[@"DJ",
           @"灯光", @"mc", @"舞台总监", @"舞编", @"A组ds", @"B组ds", @"服务员", @"咨客",
           @"营销", @"服务员领班", @"总经理", @"副总经理", @"楼面经理", @"企划", @"收银员",
           @"收银员", @"保安",@"男歌手",@"女歌手", @"其他"];
    
    
}
#pragma mark - table
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row==2){
        return 80;
    }
    if(indexPath.row==1){
        return 110;
    }
    if(indexPath.row==3){
        return 80;
    }
    return 55;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}
-(void)okFn{
    
    
    
    
    NSLog(@"kdName==%@",job_title);
    if (job_title.length==0) {
        [self.view makeToast:@"请选择职位名称" duration:1.0 position:@"center"];
        return;
    }
    if (descTF.text.length==0) {
        [self.view makeToast:@"请输入招聘详情" duration:1.0 position:@"center"];
        return;
        
    }
    
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [[MBProgressHUD showHUDAddedTo:app.window animated:YES] setLabelText:@"处理中,请稍后..."];
    [NSThread detachNewThreadSelector:@selector(doSaveRecruitFn) toTarget:self withObject:nil];
    
    
    
    
}
-(void)doSaveRecruitFn{
    NSUserDefaults*  ud=[[NSUserDefaults alloc] init];
    NSString*  uid=[ud objectForKey:@"uid"];
    NSString* uidStr=[NSString stringWithFormat:@"%@",uid];
    NSString*  longi=[ud objectForKey:@"longi"];
    NSString*  lati=[ud objectForKey:@"lati"];
    
    NSString* loginURL=HOST;
    loginURL=[loginURL stringByAppendingString:@"index.php/AppRecruit/saveRecruit"];
    NSLog(@"保存URL.loginURL==%@",loginURL);
    NSURL* url=[[NSURL alloc] initWithString:loginURL];
    ASIFormDataRequest *req=[ASIFormDataRequest requestWithURL:url];
    
    [req addPostValue:[NSString stringWithFormat:@"%@",longi] forKey:@"longi"];
    [req addPostValue:[NSString stringWithFormat:@"%@",lati] forKey:@"lati"];
    
    
    [req addPostValue:job_title forKey:@"title"];
    [req addPostValue:self.desc forKey:@"tj"];
    
    self.mp=mpTF.text;
//    [req addPostValue:[NSString stringWithFormat:@"%@",self.mp] forKey:@"mp"];
//    [req addPostValue:[NSString stringWithFormat:@"%@",emailTF.text] forKey:@"email"];
//    
//    [req addPostValue:[NSString stringWithFormat:@"%@",addrTF.text] forKey:@"addr"];
//    
//    
    [req addPostValue:uidStr forKey:@"uid"];
    
    NSString* tmpImg=[NSString stringWithFormat:@"%@",self.serverPath];
    tmpImg=[tmpImg stringByAppendingString:@".jpg"];
    [req addPostValue:pic0 forKey:@"pic0"];
    [req addPostValue:pic1 forKey:@"pic1"];
    [req addPostValue:pic2 forKey:@"pic2"];
    [req addPostValue:pic3 forKey:@"pic3"];
    
    [req addPostValue:[NSString stringWithFormat:@"%d",recruit_type] forKey:@"recruit_type"];
    
    
    
    [req startSynchronous];
    NSError *error = [req error];
    if (!error) {
        AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
        [MBProgressHUD hideHUDForView:app.window animated:YES];
        
        NSString *response = [req responseString];
        NSLog(@"保存返回结果%@",response);
        NSDictionary* dic=[response JSONValue];
        code=[[dic objectForKey:@"pk"] intValue];
        [self performSelectorOnMainThread:@selector(finishFn) withObject:nil waitUntilDone:YES];
    }
    
}
-(void)finishFn{
    if (code>0) {
        [self.view makeToast:@"发布招聘信息成功" duration:1.0 position:@"center"];
        
        
        [self.navigationController popViewControllerAnimated:NO];
        
    }else{
        [self.view makeToast:@"发布招聘信息失败" duration:1.0 position:@"center"];
        //[[NSNotificationCenter defaultCenter] postNotificationName:@"showTab" object:nil];
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if(titleTF==textField){
        NSLog(@"self.textField==%@",textField.text);
        self.kdName=textField.text;
    }
    if (linkmanTF==textField) {
        self.weight=textField.text;
    }
    
    if (emailTF==textField) {
        self.email=textField.text;
    }
    if (addrTF==textField) {
        self.addr=textField.text;
    }
    
    if (mpTF==textField) {
        self.mp=textField.text;
    }
    
    
    
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    if (descTF==textView) {
        self.desc=textView.text;
    }
}
-(void)manFn{
    self.gender=1;
    int y=10;
    int x=100;
    NSLog(@"男人..");
    if(redDotView){
        [redDotView removeFromSuperview];
    }
    redDotView=[[UIImageView alloc] initWithFrame:CGRectMake(134-87, 10+y+2,26*0.6, 26*0.6)];
    redDotView.image=[UIImage imageNamed:@"red_dot"];
    [manBtn  addSubview:redDotView];
    
    if(grayDotView){
        [grayDotView removeFromSuperview];
    }
    grayDotView=[[UIImageView alloc] initWithFrame:CGRectMake(134+x-87-x+1, 10+y+2,26*0.6, 26*0.6)];
    grayDotView.image=[UIImage imageNamed:@"gray_dot"];
    [girlBtn  addSubview:grayDotView];
    
    
    
    
}
-(void)girlFn{
    self.gender=2;
    NSLog(@"女人..");
    int y=10;
    int x=100;
    NSLog(@"男人..");
    if(redDotView){
        [redDotView removeFromSuperview];
    }
    redDotView=[[UIImageView alloc] initWithFrame:CGRectMake(134-87, 10+y+2,26*0.6, 26*0.6)];
    redDotView.image=[UIImage imageNamed:@"gray_dot"];
    [manBtn  addSubview:redDotView];
    //
    if(grayDotView){
        [grayDotView removeFromSuperview];
    }
    grayDotView=[[UIImageView alloc] initWithFrame:CGRectMake(134+x-87-x+1, 10+y+2,26*0.6, 26*0.6)];
    grayDotView.image=[UIImage imageNamed:@"red_dot"];
    [girlBtn  addSubview:grayDotView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"TodoViewController"];
    cell.tag = 1;
    if(!cell){
        cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TodoViewController"];
        
    }else{
        while ([cell.contentView.subviews lastObject] != nil) {
            
            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    int row=indexPath.row;
    int y=7;
    
    int px=5;
    if (row==0) {
        
        
        
        
        UILabel  *nameLb = [[UILabel alloc] initWithFrame:CGRectMake(7, 5, 80,46)];
        
        nameLb.text=@"职位名称";
        nameLb.font=[UIFont systemFontOfSize:14];
        nameLb.textAlignment=NSTextAlignmentLeft;
        nameLb.textColor=[UIColor blackColor];
        nameLb.backgroundColor = [UIColor clearColor];
        [cell.contentView  addSubview:nameLb];
        
        UIImageView*  bg=[[UIImageView alloc] initWithFrame:CGRectMake(87, 5, 458/2, 50)];
        bg.image=[UIImage imageNamed:@"input2"];
        [cell.contentView  addSubview:bg];
        
        //showJobTypeFn
        
        titleTF=[[UIButton alloc] initWithFrame:CGRectMake(87+px, 5+2, 458/2-4, 50-4)];
        [titleTF addTarget:self action:@selector(showJobTypeFn) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:titleTF];
        //
        job_title=[NSString stringWithFormat:@"%@",job_title];
        if (job_title) {
            UILabel  *job_titleLb = [[UILabel alloc] initWithFrame:CGRectMake(7, 5, 80,46)];
            
            job_titleLb.text=job_title;
            job_titleLb.font=[UIFont systemFontOfSize:14];
            job_titleLb.textAlignment=NSTextAlignmentCenter;
            job_titleLb.textColor=[UIColor blackColor];
            [titleTF addSubview:job_titleLb];
        }
    }
    if(row==1){
        UILabel  *lengthLb = [[UILabel alloc] initWithFrame:CGRectMake(7.0, 5,80, 45)];
        lengthLb.text=@"招聘详情";
        lengthLb.font=[UIFont systemFontOfSize:14];
        lengthLb.textAlignment=NSTextAlignmentLeft;
        lengthLb.textColor=[UIColor blackColor];
        lengthLb.backgroundColor = [UIColor clearColor];
        [cell.contentView  addSubview:lengthLb];
        
        
        UIImageView*  bg=[[UIImageView alloc] initWithFrame:CGRectMake(87, 5, 458/2, 173/2+10)];
        bg.image=[UIImage imageNamed:@"textarea2"];
        [cell.contentView  addSubview:bg];
        
        
        descTF=[[UITextView alloc] initWithFrame:CGRectMake(87+px, 5+2, 458/2-14, 173/2-4+10)];
        descTF.backgroundColor=[UIColor clearColor];
        descTF.delegate=self;
        if (self.desc) {
            descTF.text=self.desc;
        }
        [cell.contentView addSubview:descTF];
        
        
        
    }
    
    
    
    if(row==2){
        int  x=(320-4*60)/5;
        int w=60;
        addPic1Btn = [[UIButton alloc] initWithFrame:CGRectMake(x, 15, w, w)];
        [addPic1Btn setBackgroundImage:[UIImage imageNamed:@"add_pic"] forState:0];
        [addPic1Btn addTarget:self action:@selector(paiZhao1Fn) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:addPic1Btn];
        //
        addPic2Btn = [[UIButton alloc] initWithFrame:CGRectMake(x*2+w, 15, w, w)];
        [addPic2Btn setBackgroundImage:[UIImage imageNamed:@"add_pic"] forState:0];
        [addPic2Btn addTarget:self action:@selector(paiZhao2Fn) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:addPic2Btn];
        //
        addPic3Btn = [[UIButton alloc] initWithFrame:CGRectMake(x*3+w*2, 15, w, w)];
        [addPic3Btn setBackgroundImage:[UIImage imageNamed:@"add_pic"] forState:0];
        [addPic3Btn addTarget:self action:@selector(paiZhao3Fn) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:addPic3Btn];
        //
        addPic4Btn = [[UIButton alloc] initWithFrame:CGRectMake(x*4+w*3, 15, w, w)];
        [addPic4Btn setBackgroundImage:[UIImage imageNamed:@"add_pic"] forState:0];
        [addPic4Btn addTarget:self action:@selector(paiZhao4Fn) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:addPic4Btn];
        
        
        
        
        
    }
    if(row==3){
        
        okBtn=[[UIButton alloc] initWithFrame:CGRectMake((320-260)/2, 35+2, 260, 35)];
        okBtn.backgroundColor=[UIColor redColor];
        [okBtn addTarget:self action:@selector(okFn) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:okBtn];
        //
        UILabel*  okLb=[[UILabel  alloc] initWithFrame:CGRectMake(0, 0, 260, 35)];
        okLb.text=@"确   定";
        okLb.textColor=[UIColor whiteColor];
        okLb.textAlignment=NSTextAlignmentCenter;
        okLb.font=[UIFont systemFontOfSize:14];
        [okBtn addSubview:okLb];
    }
    
    
    
    
    if(row==4){
        NSString*  tk=@"1.发布信息请遵守中国的法律,不得发布淫秽,赌博等内容的信息 2.夜店中国不承担因用户违法发布信息所产生的风险.  3.一旦发现用户发布违法信息,夜店中国工作人员将在24小时内予以处理。 ";
        UITextView* tv=[[UITextView alloc] initWithFrame:CGRectMake(10, 5, 300, 80)];
        tv.text=tk;
        tv.textColor=[UIColor grayColor];
        [cell.contentView addSubview:tv];
        
    }
    
    
    
    
    
    
    
    
    
    
    
    return cell;
    
}
-(void)paiZhao1Fn{
    k=0;
    [self paiZhaoFn];
}
-(void)paiZhao2Fn{
    k=1;
    [self paiZhaoFn];
}
-(void)paiZhao3Fn{
    k=2;
    [self paiZhaoFn];
}
-(void)paiZhao4Fn{
    k=3;
    [self paiZhaoFn];
}

-(void)paiZhaoFn{
    
    
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        UIActionSheet *chooseImageSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"相册", nil];
        [chooseImageSheet showInView:self.view];
        
    }else{
        // [[NSNotificationCenter defaultCenter] postNotificationName:@"paidanFn" object:nil];
        
        
        UIActionSheet *chooseImageSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"相册", nil];
        [chooseImageSheet showInView:self.view];
    }
    
}
#pragma mark UIActionSheetDelegate Method
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    switch (buttonIndex) {
        case 0://Take picture
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"hideTab" object:nil];
            
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                
            }else{
                NSLog(@"模拟器无法打开相机");
            }
            [self presentModalViewController:picker animated:YES];
            break;
            
        case 1://From album
            [[NSNotificationCenter defaultCenter] postNotificationName:@"hideTab" object:nil];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentModalViewController:picker animated:YES];
            break;
            
        default:
            //[self dismissModalViewControllerAnimated:YES];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"showTab" object:nil];
            break;
    }
}

#pragma 拍照选择照片协议方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
    [UIApplication sharedApplication].statusBarHidden = YES;
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    //当选择的类型是图片
    if ([type isEqualToString:@"public.image"])
    {
        //先把图片转成NSData
        UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        CGSize newSize=CGSizeMake(160, 200);
        image=[self smallImg:image scaledToSize:newSize];
        if (UIImagePNGRepresentation(image) == nil)
        {
            data = UIImageJPEGRepresentation(image, 1.0);
        }
        else
        {
            data = UIImagePNGRepresentation(image);
        }
        
        //图片保存的路径
        //这里将图片放在沙盒的documents文件夹中
        NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        
        //文件管理器
        NSFileManager *fileManager = [NSFileManager defaultManager];
        
        //把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png
        [fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
        [fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];
        
        //得到选择后沙盒中图片的完整路径
        NSString* filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath,  @"/image.png"];
        self.avatar=filePath;
        
        
        //关闭相册界面
        [picker dismissModalViewControllerAnimated:YES];
        
        //创建一个选择后图片的小图标放在下方
        //类似微薄选择图后的效果
        smallimage = [[UIImageView alloc] initWithFrame:
                      CGRectMake(0, 0, 60,60)];
        
        smallimage.image = image;
        
        if(k==0){
            [addPic1Btn addSubview:smallimage];
            
        }
        if(k==1){
            [addPic2Btn addSubview:smallimage];
        }
        if(k==2){
            [addPic3Btn addSubview:smallimage];
        }
        if(k==3){
            [addPic4Btn addSubview:smallimage];
        }
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"showTab" object:nil];
        
        [self savePhotoFn];
        
    }
}
-(void)savePhotoFn{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSString* uploadURL=@"yw_uploadify.php";
    uploadURL=[HOST stringByAppendingString:uploadURL];
    
    //NSLog(@"uploadURL=%@",uploadURL);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:uploadURL]];
    
    NSDate* now = [NSDate date];
    NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
    fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    
    fmt.dateFormat = @"yyyyMMddHHmmss";
    NSString* dateString = [fmt stringFromDate:now];
    NSLog(@"%@", dateString);
    
    
    self.serverPath=[Tools md5:dateString];
    
    
    
    
    [request setPostValue:self.serverPath forKey:@"serverImgName"];
    
    NSLog(@"%d.....serverPath=%@", k,self.serverPath);
    
    self.serverPath=[self.serverPath stringByAppendingString:@".jpg"];
    if (k==0) {
        pic0=self.serverPath;
    }
    if (k==1) {
        pic1=self.serverPath;
    }
    if (k==2) {
        pic2=self.serverPath;
    }
    if (k==3) {
        pic3=self.serverPath;
    }
    
    [request setFile:self.avatar  forKey:@"filename"];
    
    
    
    //[request setValue:uid forKey:@"uid"];
    request.delegate = self;
    //
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [[MBProgressHUD showHUDAddedTo:app.window animated:YES] setLabelText:@"正在处理中，请稍后..."];
    
    
    
    
    [request startAsynchronous];
    
    
    [self savrMyAvatarFn];
}
-(void)savrMyAvatarFn{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *uid=[userDefaults objectForKey:@"uid"];
    NSString* strFlag=[userDefaults objectForKey:@"flag"];
    int flag=[strFlag intValue];
    
    [self.view makeToast:@"照片保存成功!"
                duration:1.0
                position:[NSValue valueWithCGPoint:CGPointMake(160, 210)]
     ];
    NSDictionary* dic=[NSDictionary dictionaryWithObject:self.avatar forKey:@"avatar"];
    
    
    
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [MBProgressHUD hideHUDForView:app.window animated:YES];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showTab" object:nil];
    
    
    
    
}

-(UIImage*)smallImg:(UIImage*)image scaledToSize:(CGSize)newSize
{
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
